//
//  MineCashPayViewController.m
//  MJApp
//
//  Created by wangliang on 15/3/28.
//  Copyright (c) 2015年 wangliang. All rights reserved.
//

#import "MineCashPayViewController.h"
#import "CashChangeAlipayViewController.h"

@interface MineCashPayViewController ()

@property (weak, nonatomic) IBOutlet UIButton *outButton;
@property (weak, nonatomic) IBOutlet UILabel *alipayLabel;
@property (nonatomic,strong) NSDictionary *lastDic;
@property (weak, nonatomic) IBOutlet UITextField *alipayMoneyTextField;

@end

@implementation MineCashPayViewController

- (instancetype)initWithDic:(NSDictionary *)dic {
    
    if (self = [super init]) {
        
        self.lastDic = dic;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self UI];
}

- (void)UI {
    
    self.title = self.lastDic[@"idStr"];
    self.outButton.layer.cornerRadius = CGRectGetHeight(self.outButton.frame) / 2;
    [self.outButton setTitle:self.lastDic[@"idStr"] forState:UIControlStateNormal];
    self.alipayLabel.text = self.lastDic[@"user"][@"alipay"];
    if ([self.lastDic[@"idStr"] isEqual:@"余额转出"]) {
        
        self.alipayMoneyTextField.placeholder = @"本次最多转出299元";
    }
    
}

- (IBAction)outButton:(id)sender {
    
    //确定转出
//    [self.view bringSubviewToFront:self.banView];
    
    
    if ([self.lastDic[@"idStr"] isEqual:@"余额转入"]) {
        
        [self accountToAli];
    }else {
        
        [self aliToAccount];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)aliToAccount {
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[@"user_id"] = [userInfoTool share].ID;
    dic[@"money"] = self.alipayMoneyTextField.text;
    [WLHttpRequestAfter userApplyForWithParam:dic usingSucessBlock:^(BOOL isSucess, NSDictionary *resultDictionary) {
        
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:resultDictionary[@"msg"]];
        if ([resultDictionary[@"status"] integerValue] == 1) {
            
            [self.navigationController popViewControllerAnimated:YES];
        }
    } andFailureBlock:^(NSError *resultError) {
        
        
    }];
}

- (void)accountToAli {
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[@"user_id"] = [userInfoTool share].ID;
    [WLHttpRequestAfter userGetAlipayWithParam:dic usingSucessBlock:^(BOOL isSucess, NSDictionary *resultDictionary) {
        
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:resultDictionary[@"msg"]];
    } andFailureBlock:^(NSError *resultError) {
        
    }];
}


- (IBAction)changeAlipay:(id)sender {

    [self.navigationController pushViewController:[[CashChangeAlipayViewController alloc] initWithDic:self.lastDic] animated:YES];
}

@end
